package com.luckberry.murder.mapper;

import com.luckberry.murder.entity.game.Appraise;
import com.luckberry.murder.entity.game.Game;
import com.luckberry.murder.entity.game.Participant;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GameMapper {

    /**
     * game
     */
    @Select("select * from game")
    List<Game> getGames();

    @Select("select * from game where gid = #{gid}")
    Game getGame(int gid);

    @Select("select * from game where uid = #{uid}")
    Game getGameByUser(int uid);

    @Insert("insert into game(uid, sid, hid, start, people) VALUES (#{uid}, #{sid}, #{hid}, #{start}, #{people})")
    int addGame(Game game);

    @Delete("delete game from game where gid = #{gid}")
    int deleteGame(int gid);

    @Delete("delete game from game where uid = #{uid}")
    int deleteGameByUser(int uid);

    @Update("update game set sid = #{sid}, hid = #{hid}, start = #{start}, people = #{people} where uid = #{uid}")
    int editGame(Game game);

    /**
     * appraise
     */
    @Select("select * from appraise")
    List<Appraise> getAppraises();

    @Select("select * from appraise where sid = #{sid}")
    List<Appraise> getAppraisesBySid(int sid);

    @Select("select * from appraise where aid = #{aid}")
    Appraise getAppraise(int aid);

    @Select("select * from appraise where uid = #{uid}")
    Appraise getAppraiseByUser(int uid);

    @Insert("insert into appraise(uid, sid, star, content) VALUES (#{uid}, #{sid}, #{star}, #{content})")
    int addAppraise(Appraise appraise);

    @Delete("delete appraise from appraise where aid = #{aid}")
    int deleteAppraise(int aid);

    @Update("update appraise set uid = #{uid}, uid = #{uid}, star = #{star}, content = #{content} where aid = #{aid}")
    int editAppraise(Appraise appraise);

    /**
     * participant
     */
    @Select("select * from participant")
    List<Participant> getParticipants();

    @Select("select * from participant where gid = #{gid}")
    List<Participant> getParticipantsByGame(int gid);

    @Select("select * from participant where uid = #{uid} and gid = #{gid}")
    Participant isJoin(Participant participant);

    @Select("select * from participant where uid = #{uid}")
    Participant getParticipantByUser(int uid);

    @Insert("insert into participant(uid, gid) VALUES (#{uid}, #{gid})")
    int addParticipant(Participant participant);

    @Delete("delete participant from participant where uid = #{uid}")
    int deleteParticipantByUser(int uid);

    @Delete("delete participant from participant where gid = #{gid}")
    int deleteParticipantByGame(int gid);
}
